package no.ntnu.tdt4237;

import java.util.UUID;

public class Activation {

	public static boolean createAccount(String username, String email) {
		String code = Activation.generateCode();
		String message = "Click the link below to activate your account:\n";
		message += Config.SERVER_ADDRESS + "activateuser.jsp?username=" + username + "&code=" + code;
		Boolean success = Database.saveActivation(username, code);
		if(success)
			MailSender.sendActivationCode(email, message);
		return success;
	}
	
	public static boolean recoverAccount(String username, String email) {
		String code = Activation.generateCode();
		String message = "Your account have been closed, because of too many failed logins.";
		message += "Click the link below to activate your account:\n";
		message += Config.SERVER_ADDRESS + "activateuser.jsp?username=" + username + "&code=" + code;
		Boolean success = Database.saveActivation(username, code);
		if(success)
			MailSender.sendActivationCode(email, message);
		return success;
	}
	
	public static String generateCode() {
		UUID uuid = UUID.randomUUID();
		String code = uuid.toString();
		return code;
	}
}
